<template>
  <div class="my" v-if="userInfo && userInfo.nickname">
    <!-- 个人信息 -->
    <div class="info">
      <div class="user">
        <div class="userbox">
          <div class="nickname">{{ userInfo.nickname }}</div>
          <div class="mark">{{ userInfo.intro }}</div>
        </div>
        <div class="avatar" @click="$router.push('/info')">
          <img :src="baseURL + userInfo.avatar" alt="" />
        </div>
      </div>
      <div class="data">
        <div class="item">
          <div class="num">{{ userInfo.submitNum }}</div>
          <div class="title">累计答题</div>
        </div>
        <div class="item">
          <div class="num">{{ userInfo.collectQuestions.length }}</div>
          <div class="title">收藏题目</div>
        </div>
        <div class="item">
          <div class="num">{{ userInfo.errorQuestions.length }}</div>
          <div class="title">我的错题</div>
        </div>
        <div class="item">
          <div class="num">
            {{
              Math.round(
                ((userInfo.submitNum - userInfo.errorNum) /
                  userInfo.submitNum) *
                  100
              )
            }}<span style="font-size: 12px">%</span>
          </div>
          <div class="title">正确率</div>
        </div>
      </div>
    </div>
    <!-- 其它信息 -->
    <div class="other">
      <!-- 岗位信息 -->
      <div class="position">
        <van-cell title="我的岗位" :value="userInfo.position" is-link>
          <template #icon>
            <i class="iconfont iconicon_mine_gangwei myicon"></i>
          </template>
        </van-cell>
      </div>
      <!-- 面经数据 -->
      <div class="facedata">
        <h4>面经数据</h4>
        <div class="items">
          <div class="item">
            <div class="zuori">
              昨日阅读<span class="mycolor"
                >+{{ userInfo.shareData.read.yesterday }}</span
              >
            </div>
            <div class="shuzi">{{ userInfo.shareData.read.total }}</div>
            <div class="total">阅读总数</div>
          </div>
          <div class="item">
            <div class="zuori">
              昨日获赞<span class="mycolor"
                >+{{ userInfo.shareData.star.yesterday }}</span
              >
            </div>
            <div class="shuzi">{{ userInfo.shareData.star.total }}</div>
            <div class="total">获赞总数</div>
          </div>
          <div class="item">
            <div class="zuori">
              昨日新增<span class="mycolor"
                >+{{ userInfo.shareData.comment.yesterday }}</span
              >
            </div>
            <div class="shuzi">{{ userInfo.shareData.comment.total }}</div>
            <div class="total">评论总数</div>
          </div>
        </div>
      </div>
      <!-- 其他信息 -->
      <van-cell-group class="qita">
        <van-cell title="我的面经分享" value="21" is-link>
          <template #icon>
            <i class="iconfont iconicon_mine_gangwei myicon"></i>
          </template>
        </van-cell>
        <van-cell title="我的消息" value="21" is-link>
          <template #icon>
            <i class="iconfont iconicon_mine_gangwei myicon"></i>
          </template>
        </van-cell>
        <van-cell title="收藏的题库" value="21" is-link>
          <template #icon>
            <i class="iconfont iconicon_mine_gangwei myicon"></i>
          </template>
        </van-cell>
        <van-cell title="收藏的企业" value="21" is-link>
          <template #icon>
            <i class="iconfont iconicon_mine_gangwei myicon"></i>
          </template>
        </van-cell>
        <van-cell title="我的错题" value="21" is-link>
          <template #icon>
            <i class="iconfont iconicon_mine_gangwei myicon"></i>
          </template>
        </van-cell>
        <van-cell title="收藏的面试经验" value="21" is-link>
          <template #icon>
            <i class="iconfont iconicon_mine_gangwei myicon"></i>
          </template>
        </van-cell>
      </van-cell-group>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data () {
    return {
      baseURL: process.env.VUE_APP_URL
    }
  },
  computed: {
    ...mapState(['userInfo'])
  }
}
</script>

<style lang="less" scoped>
// 设备的宽高：
//   100% 100%
// 有一种单位叫做 vw: 设备的宽度 vh：设备的高度
// 默认情况下：每种设备宽 100 vw 每种设备高 100vh
.mycolor {
  color: @color;
}
.my {
  background-color: #f7f4f5;
  height: 100vh;
  padding-bottom: 50px;
  .info {
    height: 216px;
    background: linear-gradient(45deg, #ce0031, #b8002c);
    font-size: 12px;
    color: #eaa7b7;
    padding: 0 15px;
    .user {
      padding-top: 30px;
      display: flex;
      justify-content: space-between;
      .userbox {
        .nickname {
          color: #fff;
          font-size: 21px;
        }
        .mark {
          margin-top: 10px;
        }
      }
      .avatar {
        img {
          width: 50px;
          height: 50px;
          opacity: 1;
          border: 3px solid rgba(255, 255, 255, 0.38);
          border-radius: 50%;
        }
      }
    }
    .data {
      display: flex;
      margin-top: 30px;
      .item {
        text-align: center;
        flex: 1;
        .num {
          color: #fff;
          font-size: 20px;
        }
        .title {
          margin-top: 7px;
        }
      }
    }
  }
  .other {
    padding: 0 15px;
    .position {
      margin-top: -30px;
      /deep/ .van-cell.van-cell--clickable {
        border-radius: 6px;
      }
      .myicon {
        margin-right: 8px;
      }
    }
    .facedata {
      background-color: #fff;
      border-radius: 6px;
      margin-top: 10px;
      h4 {
        font-size: 14px;
        padding: 19px 15px;
      }
      .items {
        display: flex;
        padding-bottom: 16px;
        .item {
          flex: 1;
          text-align: center;
          .zuori {
            font-size: 12px;
            color: #b4b4bd;
          }
          .shuzi {
            font-size: 20px;
            padding: 10px 0 5px 0;
          }
          .total {
            font-size: 14px;
            color: #545671;
          }
        }
      }
    }
    .qita {
      margin-top: 10px;
      .myicon {
        margin-right: 6px;
      }
    }
  }
}
</style>
